﻿// owner 蒋家伟

#pragma once
#include "WeakReference.h"
#include "DataSchema_home.h"

namespace jsdk
{
    class IElement;
    class ElementId;
}

namespace jsdk
{
    class DATASCHEMA_EXPORT IDocument : public WeakReference
    {
        DEFINE_DRIVER_BASE(IDocument)
    public:
        virtual ~IDocument() {}

        /// \ 创建一个新的空文档
        static IDocument* create();

        /// \ brief 加载文档
        /// \ in loadPath 文档所在的路径
        static IDocument* Load(const std::wstring& loadPath);

#pragma region 基础接口
        /// \ breif 通过Id获取element对象
        virtual IElement* getElement(const ElementId& elementId) = 0;
        virtual const IElement* getElement(const ElementId& elementId) const = 0;

        /// \ brief 删除Element对象
        /// \ in elementId 待删除的对象
        /// \ return 正确删除则返回true
        virtual bool deleteElement(const ElementId& elementId) = 0;

        /// \ brief 删除一组Element对象
        /// \ in elementIds 待删除的对象
        /// \ out pDeleteFailElementId 删除失败的对象
        /// \ return 全部删除则删除成功，否则失败
        virtual bool deleteElements(const std::set<ElementId>& elementIds, std::set<ElementId>* pDeleteFailElementId = nullptr) = 0;

        /// \ brief 获取文档中所有的ElementId
        virtual std::set<ElementId> getAllElementId() const = 0;
#pragma region 基础接口


#pragma region 序列化与反序列化
        /// \ brief 文档保存
        /// \ in savePath 保存路径
        virtual bool save(const std::wstring& savePath) const = 0;
#pragma region 序列化与反序列化

        using RunTimeId = uint64_t;
        /// \ brief 获取文档运行时ID
        virtual RunTimeId getRunTimeId() const = 0;
    };
}
